<!DOCTYPE html>
<html lang="en" style="padding:5px;box-sizing:border-box;height:100%;width:100%">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="ThemeBucket">
    <link rel="shortcut icon" href="#" type="image/png">
    <title>登陆</title>
    <link href="static/plugins/adminex/css/style.css" rel="stylesheet">
    <link href="static/css/element-2.0.css" rel="stylesheet">
    <style>
    *:focus {
             outline: none !important;
        }
        a :hover{
           color:#000; 
        }
        #submitCheckOut :hover{
            color:#fff;
        }
    </style>
</head>

<body style="height:100%;width: 100%;background-color: rgba(0, 0, 0, 0);color:#fff;margin:0px;padding:0px;-webkit-user-select: none;box-shadow: 0 1px 6px 1px rgba(0, 0, 0, 0.3);border-radius: 3px;" ondragstart="return false" ondrop ="return false" ondragover="return false">



<div class="container" style="background: #65cea7 url(./static/img/login-bg.jpg) no-repeat fixed;border-radius: 3px;width: 100%;height: 100%;">
    <div style="height:50px;text-align:center;-webkit-app-region: drag">
        <div style="font-size: 20px;padding-top: 10px;display: block;float: left;">
        美易通<span id="version" style="padding-left:5px;font-size: 12px"></span>
        </div>
        <i style="float:right;font-size: 30px;padding: 10px 0px;cursor: pointer;-webkit-app-region: no-drag" onclick="closeWindow()" class="el-icon-error"></i>
    </div>

    <form class="form-signin" id="signin" style="margin:40px 10px 0px 10px">
        <div class="form-signin-heading text-center">
            <h1 class="sign-title">请登录</h1>
            <img style="width:110px;" src="static/img/login-logo.png" alt=""/>
        </div>
        <div class="login-wrap">
            <input type="text" id="username" class="form-control" name="username" placeholder="用户名" autofocus>
            <input type="password" id="password" class="form-control" name="password" placeholder="密码">
            
            <a class="btn btn-lg btn-login btn-block" href="javascript:;" onclick="login()" style="border:none;background: rgb(234, 234, 236);padding: 0px; position:relative;text-decoration:none;">
                <div id="percent" style="background: #4fd4a2;border-radius: 6px;width:0%;position: absolute;height:39px">
                    <span id="submitCheckOut" style="width:288px;display:block;font-size: 12px;line-height:39px;color: rgb(228, 4, 118)"></span>
                </div>
                <span style="color: rgb(234, 234, 236)">确定</span>
            </a>
        </div>

        <!-- Modal -->
        <div aria-hidden="true" aria-labelledby="myModalLabel" role="dialog" tabindex="-1" id="myModal" class="modal fade">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                        <h4 class="modal-title">忘记密码了？</h4>
                    </div>
                    <div class="modal-body">
                        <p>请输入注册邮箱重新设置密码..</p>
                        <input type="text" name="email" placeholder="Email" autocomplete="off" class="form-control placeholder-no-fix">

                    </div>
                    <div class="modal-footer">
                        <button data-dismiss="modal" class="btn btn-default" type="button">取消</button>
                        <button class="btn btn-primary" type="button">提交</button>
                    </div>
                </div>
            </div>
        </div>
        <!-- modal -->
    </form>
</div>

<!-- Placed js at the end of the document so the pages load faster -->

</body>
<script type="text/javascript">
var C = require('./src/common/common.js')
const config = require('./package.json')
const {ipcRenderer, remote} = require('electron')
document.getElementById('version').innerHTML = config.smallVersion
localStorage.clear()

let canSubmit = false
let submitCheckOut = document.getElementById('submitCheckOut')
let percent = document.getElementById('percent')

// 初始化更新操作
submitCheckOut.innerHTML = '准备检查更新！'
// 发送更新请求

setTimeout(function () {
  ipcRenderer.send('_checkUpdates')  
})

// 接收更新消息
ipcRenderer.on('_checkUpdatesMessage', (e, arg) => {
    console.log(arg)
    submitCheckOut.innerHTML = arg.msg
    percent.style.width = arg.percent
    if (arg.success)  {
        percent.innerHTML = '<i class="fa fa-check"></i>'
        // init()
        canSubmit = true
        if (arg.isreStart) {
            alert('更新完毕，点击确定重启应用！')
            remote.app.relaunch()
            remote.app.exit(0)
        }
    }
})





// 暂时设置第二种登录方式
async function login () {
    if (!canSubmit) return false
    let username = document.getElementById('username').value
    let password = document.getElementById('password').value
    if ('' == username) {
        C.error('请填写用户名')
        return false
    }
    if ('' == password) {
        C.error('请填写密码')
        return false
    }
    const machine = require('node-machine-id')
    let machineid = machine.machineIdSync()
    canSubmit = false
    percent.innerHTML = '<i class="el-icon-loading"></i>'
    let res = await C.ajax('/login/public/newsignin',{username: username, password: password, machineid: machineid}, 'post')
    percent.innerHTML = '<i class="fa fa-check"></i>'
    canSubmit = true
    // 存储token
    if (res) {
        C.setLocalStorage('usertoken', res.data.token)
        C.setLocalStorage('permission',res.data.permi.gradepermission)
        if (1 == res.data.floor) {
            C.openBrowserWindow('/', {}, {
              transparent: true,
              frame: false,
              // openDevTools: true,
              width: 1600,
              height: 900,
              useSpa: true,
              spaModel: 'shop'
            })
        } else {
            C.openBrowserWindow('html/organization/index.html', {}, {width: 1600, height: 900})
        }
        C.closewin()
    }
}

window.onkeyup = function (e) {
    if (e.which == 13) login()
}



function closeWindow () {
    C.closewin()
}
// 发送主窗口（--兼容图标）
ipcRenderer.send('_changeMainWindow', remote.getCurrentWindow().id)
</script>
</html>